package com.njtech.smartuniversity.controller;

import com.github.pagehelper.PageInfo;
import com.njtech.smartuniversity.bean.AssistantBean;
import com.njtech.smartuniversity.bean.CaseBean;
import com.njtech.smartuniversity.bean.CaseobjBean;
import com.njtech.smartuniversity.bean.UserBean;
import com.njtech.smartuniversity.bean.InformBean;
import com.njtech.smartuniversity.service.AssistantService;
import com.njtech.smartuniversity.service.CaseService;
import com.njtech.smartuniversity.service.CaseobjService;
import com.njtech.smartuniversity.service.UserService;
import com.njtech.smartuniversity.service.InformService;
import com.njtech.smartuniversity.util.JsonResult;
import com.njtech.smartuniversity.util.JsonUtil;
import com.njtech.smartuniversity.util.NumberUtil;
import com.njtech.smartuniversity.util.PdfUtilsPic;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;


/**
 * Created by ritchie on 6/25/18
 */

@RestController
@Api(value = "/api/index", tags = {"主页"}, description = "主页相关")
@RequestMapping("/api/index")
public class IndexController {

    @Autowired
    AssistantService mAssistantService;
    @Autowired
    CaseService mCaseService;
    @Autowired
    CaseobjService mCaseobjService;
    @Autowired
    UserService mUserService;
    @Autowired
    InformService mInformService;

//    @GetMapping("/{id}")
//    @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_CUSTOMER') or hasRole('ROLE_MERCHANT')")
//    @ApiOperation(value = "单个用户查询接口", notes = "使用ID查询用户")
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "用户ID(学号/工号)", name = "id", dataType = "String", paramType = "path", required = true)
//    })
//    @ApiResponses({
//            @ApiResponse(code = 400, message = "请求参数有误"),
//            @ApiResponse(code = 401, message = "未授权"),
//            @ApiResponse(code = 403, message = "禁止访问"),
//            @ApiResponse(code = 404, message = "请求路径不存在"),
//            @ApiResponse(code = 500, message = "服务器内部错误")
//    })
//    public JsonResult GetUser(@PathVariable("id") String id) {
//        UserBean user = mUserService.selectByUserId(id);
//        if (user != null) {
//            return new JsonUtil().successDataDefault(user);
//        }
//
//        return new JsonUtil().wrongNoDataWithMessage("不存在该地域");
//    }


    //案件数统计
    @GetMapping("/casenumber/{area}")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "案件数总计接口", notes = "获取所有协查信息")
    @ApiImplicitParam(value = "地域id", name = "area", dataType = "int", paramType = "path", required = true)
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult ListCases(@PathVariable("area") int area
    ) {
            return new JsonUtil().successDataDefault(mCaseService.casenumber(area));
    }


    @GetMapping("/inform/")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "主页通知接口", notes = "获取最新4条通知")
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult ListPageInform() {

        List<InformBean> areaBeanList = mInformService.selectlist();
        if (areaBeanList != null) {
            return new JsonUtil().successDataDefault(areaBeanList);
        }
        return new JsonUtil().wrongNoDataWithMessage("暂无通知通告");

    }

    @GetMapping("/selet4/{area}")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "主页4代签收接口", notes = "获取最新4条通知")
    @ApiImplicitParam(value = "地域id", name = "area", dataType = "int", paramType = "path", required = true)
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult ListPageAssion4(@PathVariable("area") int area) {

        List<AssistantBean>  areaBeanList = mAssistantService.select4(area);
        if (areaBeanList != null) {
            return new JsonUtil().successDataDefault(areaBeanList);
        }
        return new JsonUtil().wrongNoDataWithMessage("暂无通知通告");

    }


    @GetMapping("/chaxun/{area}")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "主页4代签收接口", notes = "获取最新4条通知")
    @ApiImplicitParam(value = "地域id", name = "area", dataType = "int", paramType = "path", required = true)
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult chaxun(@PathVariable("area") int area) {

        int  areaBeanList = mAssistantService.countByExample(area,1);
        return new JsonUtil().successDataDefault(areaBeanList);


    }

    @GetMapping("/qianshou/{area}")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "主页4代签收接口", notes = "获取最新4条通知")
    @ApiImplicitParam(value = "地域id", name = "area", dataType = "int", paramType = "path", required = true)
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult qianshou(@PathVariable("area") int area) {

        int  areaBeanList = mAssistantService.countByExample(area,5);
        return new JsonUtil().successDataDefault(areaBeanList);


    }

    @GetMapping("/cheng/{area}")
    @PreAuthorize("hasRole('ROLE_MERCHANT')")
    @ApiOperation(value = "主页4代签收接口", notes = "获取最新4条通知")
    @ApiImplicitParam(value = "地域id", name = "area", dataType = "int", paramType = "path", required = true)
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数有误"),
            @ApiResponse(code = 401, message = "未授权"),
            @ApiResponse(code = 403, message = "禁止访问"),
            @ApiResponse(code = 404, message = "请求路径不存在"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public JsonResult cheng(@PathVariable("area") int area) {

        int  areaBeanList = mAssistantService.countByExample(area,6);
        return new JsonUtil().successDataDefault(areaBeanList);


    }








}
